import {createRouter, createWebHashHistory} from "vue-router";

const routes = [
    {path: "/", redirect: "/route"},
    {
        path: "/index",
        component: import("../page/indexPage/indexPage.vue"),
        children:[
            {
                path: "/index/schoolManage",
                component: import("../page/schoolManage/schoolManage.vue"),
            },
            {
                path: "/index/studentManage",
                component: import("../page/studentManage/studentManage.vue"),
            },
            {
                path: "/index/home",
                component: import("../page/home/home.vue"),
            },
            {
                path: "/index/schoolInfo",
                component: import("../page/schoolInfo/schoolInfo.vue"),
            }
        ]
    },
    {
        path: "/lotteryPage", component: import("../page/lotteryPage/LotteryPage.vue"),
    }
]

export const router = createRouter({
    history: createWebHashHistory(),
    routes: routes,
    mode: 'history',
})

router.beforeEach((to, from, next) => {
    if (to.path === '/route') {
        return next('/index')
    }
    // if (to.path === '/index') {
    //     return next('/index/home')
    // }

    if (to.path === '/login') {
        return next()
    }

    // var localToken = window.localStorage.getItem('token');
    // if (!localToken) {
    //     console.log("login")
    //     return next('/login')
    // }

    next()
})

export default router

